"""
轮播图相关的 Pydantic 模式
"""
from typing import Optional
from pydantic import BaseModel, Field
from datetime import datetime


class BannerBase(BaseModel):
    """轮播图基础模式"""
    title: str = Field(..., max_length=200, description="轮播图标题")
    subtitle: Optional[str] = Field(None, max_length=500, description="副标题")
    image_url: str = Field(..., max_length=500, description="图片URL")
    link_url: Optional[str] = Field(None, max_length=500, description="链接URL")
    description: Optional[str] = Field(None, description="描述文本")
    is_active: bool = Field(default=True, description="是否激活")
    sort_order: int = Field(default=0, description="排序顺序")


class BannerCreate(BannerBase):
    """创建轮播图请求模式"""
    class Config:
        schema_extra = {
            "example": {
                "title": "专业环境工程咨询",
                "subtitle": "为您提供全方位的环境解决方案",
                "image_url": "/images/banner1.jpg",
                "link_url": "/services",
                "description": "我们拥有专业的环境工程团队",
                "is_active": True,
                "sort_order": 1
            }
        }


class BannerUpdate(BaseModel):
    """更新轮播图请求模式"""
    title: Optional[str] = Field(None, max_length=200, description="轮播图标题")
    subtitle: Optional[str] = Field(None, max_length=500, description="副标题")
    image_url: Optional[str] = Field(None, max_length=500, description="图片URL")
    link_url: Optional[str] = Field(None, max_length=500, description="链接URL")
    description: Optional[str] = Field(None, description="描述文本")
    is_active: Optional[bool] = Field(None, description="是否激活")
    sort_order: Optional[int] = Field(None, description="排序顺序")


class BannerResponse(BannerBase):
    """轮播图响应模式"""
    id: int
    created_at: datetime
    updated_at: Optional[datetime] = None

    class Config:
        from_attributes = True


class BannerListResponse(BaseModel):
    """轮播图列表响应模式"""
    items: list[BannerResponse]
    total: int
    page: int
    size: int
    pages: int